/************************************************************************

								Heroes IV
					  Copyright 2000, The 3DO Company

	------------------------------------------------------------------
  						 bitmap_layer.h

	$Header: /resource_editor/bitmap_group.h $

	$NoKeywords: $

 ************************************************************************/

#if !defined(BITMAP_GROUP_H_INCLUDED)
#define BITMAP_GROUP_H_INCLUDED

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "bitmap_layer.h"
#include "resource_traits.h"

class t_progress_handler;

// --------------------------------------------------------
// group of 24-bit palette bitmap layers
// --------------------------------------------------------
class t_bitmap_group_24 : public std::vector<t_bitmap_layer_24>
{
public:
	typedef t_bitmap_layer_24 t_layer_type;

	t_screen_rect get_rect() const;
	void offset( t_screen_point delta ); // move all bitmap rects by a given amount
	bool read( std::streambuf& buffer, t_progress_handler* handler );
	bool write( std::streambuf& buffer ) const;
};

inline bool read( std::streambuf& buffer, t_bitmap_group_24& group )
{
	return group.read( buffer, 0 );
}

inline bool read( std::streambuf& buffer, t_bitmap_group_24& group, 
				  t_progress_handler* handler )
{
	return group.read( buffer, handler );
}


// --------------------------------------------------------
// group of 16-bit palette bitmap layers
// --------------------------------------------------------
// note: this has a nonstandard [] operator to allow common usage in the image_sequence
// templates with t_bitmap_group_24.
typedef t_shared_ptr<t_bitmap_layer> t_shared_layer_ptr;

// this intermediate class only exists due to a stupid compiler bug which prevents
// the recognition of certain syntax
class t_bitmap_group_base : public std::vector<t_shared_layer_ptr>
{
};

class t_bitmap_group : public t_bitmap_group_base
{
public:
	typedef t_bitmap_layer t_layer_type;

	t_bitmap_group();
	virtual ~t_bitmap_group();
	explicit t_bitmap_group( t_bitmap_group_24 const& source );

	iterator				find_iterator( std::string const& name );
	const_iterator			find_iterator( std::string const& name ) const;
	t_bitmap_layer*	        find( std::string const& name );
	t_bitmap_layer const*	find( std::string const& name ) const;
	int                     get_alpha_depth() const;
	t_screen_rect			get_rect() const;
	void					offset( t_screen_point delta ); // move all bitmap rects by a given amount
	void                    push_back( t_bitmap_layer* layer );
	t_bitmap_layer&         operator[] (int arg);  
	t_bitmap_layer const&   operator[] (int arg) const;
};

inline t_bitmap_group::t_bitmap_group()
{
}

inline void t_bitmap_group::push_back( t_bitmap_layer* layer )
{
	t_shared_layer_ptr arg( layer );

	t_bitmap_group_base::push_back( arg );
}

inline t_bitmap_layer& t_bitmap_group::operator[] (int arg)
{
	return **(begin() + arg);
}

inline t_bitmap_layer const& t_bitmap_group::operator[] (int arg) const
{
	return **(begin() + arg);
}

template <>
struct t_resource_traits<t_bitmap_group_24>
{
	static char const prefix[];
	static char const extension[];
};



#endif // BITMAP_GROUP_H_INCLUDED